package parsing;

import database.Article;
import database.Story;

/**
 * This class is in charge of determining what category on the website Articles should be placed into.
 * @author Jamison Bradley
 */
public class CategoryChooser {
	
	public static String WORLD = "World News";
	public static String TECHNOLOGY = "Technology";
	public static String OTHER = "Other";
	
	
	/**
	 * Sets the Story's category to the category that it will be placed under on the website.
	 * @param s is the Story that needs to have its category value set.
	 * @param a is the first article that was associated with a Story, it will be used to determine what category on our website
	 * the Story will be placed under.
	 */
	public static void setCategory(Story s, Article a){
		String source = a.getSource();
		String category = a.getCategory();
		
		if ("CNN".equals(source)){
			if ("world".equals(category) || "us".equals(category)){
				s.setCategory(WORLD);
			}
			else if ("tech".equals(category)){
				s.setCategory(TECHNOLOGY);
			}
			else{
				s.setCategory(OTHER);
			}
		}
		else if ("BBC".equals(source)){
			if ("Africa".equals(category) || "Europe".equals(category) || "US & Canada".equals(category) || "Asia".equals(category)
					|| "Middle East".equals(category) || "India".equals(category) || "Latin America & Caribbean".equals(category)
					|| "Wales".equals(category) || "UK".equals(category) || "World".equals(category)){
				s.setCategory(WORLD);
			}
			else if ("Science & Environment".equals(category) || "Technology".equals(category)){
				s.setCategory(TECHNOLOGY);
			}
			else{
				s.setCategory(OTHER);
			}
		}
		else if ("The Guardian".equals(source)){
			if ("World news".equals(category) || "UK news".equals(category) || "News".equals(category)){
				s.setCategory(WORLD);	
			}
			else if ("Technology".equals(category) || "Science".equals(category)){
				s.setCategory(TECHNOLOGY);
			}
			else{
				s.setCategory(OTHER);
			}
		}
		else{
			throw new IllegalArgumentException("The Article a does not have a source value associated with it.");
		}
	}
}
